#ifndef DBMYSQL_H
#define DBMYSQL_H

#include <QtSql\QSQLDatabase>
#include <QString>

#include "db.h"

#define MYSQL_CREATE_TABLE_BANS				"CREATE TABLE IF NOT EXISTS bans"										\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"server VARCHAR(100) NOT NULL,"										\
												"name VARCHAR(15) NOT NULL,"										\
												"ip VARCHAR(15),"													\
												"date DATETIME NOT NULL,"											\
												"gamename VARCHAR(31),"												\
												"banner VARCHAR(15) NOT NULL,"										\
												"reason VARCHAR(255),"												\
												"gamecount INT,"													\
												"expiredate DATETIME NOT NULL"										\
											")"

#define MYSQL_CREATE_TABLE_DOTAGAMES		"CREATE TABLE IF NOT EXISTS dotagames"									\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"gameid INT NOT NULL,"												\
												"winner INT NOT NULL,"												\
												"min INT NOT NULL,"													\
												"sec INT NOT NULL"													\
											")"

#define MYSQL_CREATE_TABLE_DOTAPLAYERS		"CREATE TABLE IF NOT EXISTS dotaplayers"								\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"gameid INT NOT NULL,"												\
												"color INT NOT NULL,"												\
												"kills INT NOT NULL,"												\
												"deaths INT NOT NULL,"												\
												"creepkills INT NOT NULL,"											\
												"creepdenies INT NOT NULL,"											\
												"assists INT NOT NULL,"												\
												"gold INT NOT NULL,"												\
												"neutralkills INT NOT NULL,"										\
												"item1 CHAR(4) NOT NULL,"											\
												"item2 CHAR(4) NOT NULL,"											\
												"item3 CHAR(4) NOT NULL,"											\
												"item4 CHAR(4) NOT NULL,"											\
												"item5 CHAR(4) NOT NULL,"											\
												"item6 CHAR(4) NOT NULL,"											\
												"hero CHAR(4) NOT NULL,"											\
												"newcolor INT NOT NULL,"											\
												"towerkills INT NOT NULL,"											\
												"raxkills INT NOT NULL,"											\
												"courierkills INT NOT NULL,"										\
												"apm INT NOT NULL,"													\
												"INDEX(gameid, color)"												\
											")"

#define MYSQL_CREATE_TABLE_GAMEPLAYERS		"CREATE TABLE IF NOT EXISTS gameplayers"								\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"gameid INT NOT NULL,"												\
												"server VARCHAR(100) NOT NULL,"										\
												"name VARCHAR(15) NOT NULL,"										\
												"ip VARCHAR(15) NOT NULL,"											\
												"spoofed INT NOT NULL,"												\
												"reserved INT NOT NULL,"											\
												"loadingtime INT NOT NULL,"											\
												"`left` INT NOT NULL,"												\
												"leftreason VARCHAR(100) NOT NULL,"									\
												"team INT NOT NULL,"												\
												"color INT NOT NULL,"												\
												"INDEX(gameid)"														\
											")"

#define MYSQL_CREATE_TABLE_GAMES			"CREATE TABLE IF NOT EXISTS games"										\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"server VARCHAR(100) NOT NULL,"										\
												"map VARCHAR(100) NOT NULL,"										\
												"datetime DATETIME NOT NULL,"										\
												"gamename VARCHAR(31) NOT NULL,"									\
												"ownername VARCHAR(15) NOT NULL,"									\
												"ownerserver VARCHAR(100) NOT NULL,"								\
												"duration INT NOT NULL,"											\
												"gamestate INT NOT NULL,"											\
												"creatorname VARCHAR(15) NOT NULL,"									\
												"creatorserver VARCHAR(100) NOT NULL"								\
											")"

#define MYSQL_CREATE_TABLE_SCORES			"CREATE TABLE IF NOT EXISTS scores"										\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"category VARCHAR(25) NOT NULL,"									\
												"name VARCHAR(15) NOT NULL,"										\
												"server VARCHAR(100) NOT NULL,"										\
												"score REAL NOT NULL"												\
											")"

#define MYSQL_CREATE_TABLE_USERS			"CREATE TABLE IF NOT EXISTS users"										\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"server VARCHAR(100) NOT NULL,"										\
												"name VARCHAR(15) NOT NULL,"										\
												"voucher VARCHAR(15) NOT NULL,"										\
												"access BIGINT UNSIGNED NOT NULL"									\
											")"

#define MYSQL_CREATE_TABLE_W3MMDPLAYERS		"CREATE TABLE IF NOT EXISTS w3mmdplayers"								\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"category VARCHAR(25) NOT NULL,"									\
												"gameid INT NOT NULL,"												\
												"pid INT NOT NULL,"													\
												"name VARCHAR(15) NOT NULL,"										\
												"flag VARCHAR(32) NOT NULL,"										\
												"leaver INT NOT NULL,"												\
												"practicing INT NOT NULL"											\
											")"	

#define MYSQL_CREATE_TABLE_W3MMDVARS		"CREATE TABLE IF NOT EXISTS w3mmdvars"									\
											"("																		\
												"id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,"						\
												"botid INT NOT NULL,"												\
												"gameid INT NOT NULL,"												\
												"pid INT NOT NULL,"													\
												"varname VARCHAR(25) NOT NULL,"										\
												"value_int INT DEFAULT NULL,"										\
												"value_real REAL DEFAULT NULL,"										\
												"value_string VARCHAR(100) DEFAULT NULL"							\
											")"

class CDBMySQL: public CDatabase
{
private:
	bool m_ThreadGoal;

	QString m_DatabaseName;

public:
	CDBMySQL(const QString &server, const QString &database, const QString &user, const QString &password, quint16 port);
	~CDBMySQL();

	virtual void run();

	virtual void SetThreadGoal(bool goal)														{ m_ThreadGoal = goal; }
};

#endif // DBMYSQL_H
